package org.jeecg.modules.bigscreen.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.jeecg.modules.basic.demo.apartment.entity.LwgyBaseApartment;
import org.jeecg.modules.basic.demo.apartment.service.ILwgyBaseApartmentService;
import org.jeecg.modules.electricity.service.ILwgyJointElectricityService;
import org.jeecg.modules.electricity.service.ILwgyJointViolationvelectService;
import org.jeecg.modules.water.entity.LwgyJointWaterConfiguration;
import org.jeecg.modules.water.service.ILwgyJointWaterConfigurationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Description: 数据大屏
 * @Author: sn
 * @Date: 2024-05-18
 * @Version: V1.0
 */
@Service
@Slf4j
public class BigWaterScreenService {


    @Autowired
    private ILwgyBaseApartmentService iLwgyBaseApartmentService;

    @Autowired
    private ILwgyJointWaterConfigurationService lwgyJointWaterConfigurationService;

    @Autowired
    private ILwgyJointElectricityService lwgyJointElectricityService;
    @Autowired
    private ILwgyJointViolationvelectService LwgyJointViolationvelectService;

    public Map<String, Object> getData() {


        long totalStart = System.currentTimeMillis();
        Map<String, Object> result = new HashMap<>(16);
        //初始数据
        result.put("fjhNum", 0);
        result.put("waterNbNum", 0);
        result.put("waterLoraNum", 0);
        result.put("powerNum", 0);
        result.put("waterErrNum", 0);
        result.put("powerErrNum", 0);

        //获取总床位数据
        long start1 = System.currentTimeMillis();
        QueryWrapper<LwgyBaseApartment> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("type","room");
        queryWrapper.eq("room_type","hotel_room");
        List<LwgyBaseApartment> fjlist = iLwgyBaseApartmentService.list(queryWrapper);
        result.put("fjhNum", fjlist.size());
        List<LwgyJointWaterConfiguration> sblist =lwgyJointWaterConfigurationService.list();

        List<LwgyJointWaterConfiguration> listnb = sblist.stream().filter(item -> { return StringUtils.equals(item.getDeviceType(),"0");//nb 是 0.
        }).collect(Collectors.toList());
        List<LwgyJointWaterConfiguration> listlora = sblist.stream().filter(item -> { return StringUtils.equals(item.getDeviceType(),"1");//lora 是 1.
        }).collect(Collectors.toList());
        result.put("waterNbNum", listnb.size());
        result.put("waterLoraNum",listlora.size());
        //因为lora目前没有信号值。watererrNum 先不写
        // List<LwgyJointWaterConfiguration> listerr = sblist.stream().filter(item -> { return Integer.parseInt(item.getSignalstrength())<10;//lora 是 1.
         //       }).collect(Collectors.toList());
        // result.put("waterErrNum", listerr.size());

      /*  List<LwgyJointElectricity> powerList = lwgyJointElectricityService.list();
        result.put("powerNum", powerList.size());

        List<LwgyJointViolationvelect> powerErrorList = LwgyJointViolationvelectService.list();
        result.put("powerErrNum", powerErrorList.size());*/

        long totalEnd = System.currentTimeMillis();
        log.info("总耗时："+(totalEnd-totalStart));
        return result;
    }

}
